@layout("/common/_container.html"){
<div class="layui-card">
  <div class="layui-card-body">
  <table class="layui-table layui-form" id="test" lay-filter="test">
	  <thead>
	    <tr>
	      <th>消息类型</th>
	      <th>消息接收人</th>
	      <th>站内通知</th>
	      <th>邮件通知</th>
	      <th>操作</th>
	    </tr> 
	  </thead>
	  <tbody>
	  	@for(msgConfigMap in list){
		  	@if(msgConfigMap.msgType == 1){
			  	<tr>
			      <td colspan="5"><h3>用户消息</h3></td>
			    </tr>
			    @for(msgConfig in msgConfigMap.msgConfigList){
			    <tr>
			      <td>${msgConfig.tip}</td>
			      <td>${msgConfig.roleNames}</td>
			      <td>
			      <input type="checkbox" name="ifStation" id="ifStation" value="${msgConfig.msgConfigId}" lay-skin="switch" lay-text="是|否" lay-filter="ifStation" ${msgConfig.ifStation == 1 ? 'checked' : ''}>
			      </td>
			      <td>
			      <input type="checkbox" name="ifEmail" id="ifEmail" value="${msgConfig.msgConfigId}" lay-skin="switch" lay-text="是|否" lay-filter="ifEmail" ${msgConfig.ifEmail == 1 ? 'checked' : ''}>
			      </td>
			      <td><a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="review" title="修改" onclick="review(${msgConfig.msgConfigId})">修改</a></td>
			    </tr>
			    @}
		    @}
		    @if(msgConfigMap.msgType == 2){
			  	<tr>
			      <td colspan="5"><h3>服务消息</h3></td>
			    </tr>
			    @for(msgConfig in msgConfigMap.msgConfigList){
			    <tr>
			      <td>${msgConfig.tip}</td>
			      <td>${msgConfig.roleNames}</td>
			      <td>
			      <input type="checkbox" name="ifStation" id="ifStation" value="${msgConfig.msgConfigId}" lay-skin="switch" lay-text="是|否" lay-filter="ifStation" ${msgConfig.ifStation == 1 ? 'checked' : ''}>
			      </td>
			      <td>
			      <input type="checkbox" name="ifEmail" id="ifEmail" value="${msgConfig.msgConfigId}" lay-skin="switch" lay-text="是|否" lay-filter="ifEmail" ${msgConfig.ifEmail == 1 ? 'checked' : ''}>
			      </td>
			      <td><a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="review" title="修改" onclick="review(${msgConfig.msgConfigId})">修改</a></td>
			    </tr>
			    @}
		    @}
		    @if(msgConfigMap.msgType == 3){
			  	<tr>
			      <td colspan="5"><h3>订单消息</h3></td>
			    </tr>
			    @for(msgConfig in msgConfigMap.msgConfigList){
			    <tr>
			      <td>${msgConfig.tip}</td>
			      <td>${msgConfig.roleNames}</td>
			      <td>
			      <input type="checkbox" name="ifStation" id="ifStation" value="${msgConfig.msgConfigId}" lay-skin="switch" lay-text="是|否" lay-filter="ifStation" ${msgConfig.ifStation == 1 ? 'checked' : ''}>
			      </td>
			      <td>
			      <input type="checkbox" name="ifEmail" id="ifEmail" value="${msgConfig.msgConfigId}" lay-skin="switch" lay-text="是|否" lay-filter="ifEmail" ${msgConfig.ifEmail == 1 ? 'checked' : ''}>
			      </td>
			      <td><a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="review" title="修改" onclick="review(${msgConfig.msgConfigId})">修改</a></td>
			    </tr>
			    @}
		    @}
	    @}
	  </tbody>
  </table>
  </div>
</div>

<script>
layui.config({
	base: Feng.ctxPath + "/static/layuiadmin/" //静态资源所在路径
}).extend({
	index: 'lib/index' //主入口模块
}).use(['index', 'layer','table', 'form'],function(){
	
	var $ = layui.$
  	,form = layui.form
  	,table = layui.table;
	
	//监听性别操作
    form.on('switch(ifStation)', function(obj){
    	var field = {
    		msgConfigId: this.value,
    		ifStation: (obj.elem.checked == true ? 1:0)
    	};
        var loadingIndex = layer.msg('数据加载中', {icon: 16, time: 0 ,shade: 0.01});
		var ajax = new $ax(Feng.ctxPath + "/msgConfig/admin/set", function (data) {
            Feng.success("设置成功!");
            table.reload('table',{
          	  done: function(res){
     		    	layer.close(loadingIndex);
     	          }
             }); //数据刷新
            layer.close(index); //关闭弹层
        }, function (data) {
            Feng.error("设置失败!" + data.responseJSON.message + "!");
        },true);
        ajax.setData(field);
        ajax.start();
    });
	
    form.on('switch(ifEmail)', function(obj){
    	var field = {
       		msgConfigId: this.value,
       		ifEmail: (obj.elem.checked == true ? 1:0)
       	};
        var loadingIndex = layer.msg('数据加载中', {icon: 16, time: 0 ,shade: 0.01});
   		var ajax = new $ax(Feng.ctxPath + "/msgConfig/admin/set", function (data) {
               Feng.success("设置成功!");
               table.reload('table',{
             	  done: function(res){
        		    	layer.close(loadingIndex);
        	          }
                }); //数据刷新
               layer.close(index); //关闭弹层
           }, function (data) {
               Feng.error("设置失败!" + data.responseJSON.message + "!");
           },true);
           ajax.setData(field);
           ajax.start();
    });
	
});

function review(msgConfigId){
	var loadingIndex = layer.msg('数据加载中', {icon: 16, time: 0 });
    layer.open({
      type: 2
      ,title: '消息配置用户'
      ,content: Feng.ctxPath + '/msgConfig/admin/receive/'+msgConfigId
      ,area: ['720px', '390px']
      ,btn: ['确定', '取消']
      ,yes: function(index, layero){
        var iframeWindow = window['layui-layer-iframe'+ index]
        ,submitID = 'msgConfig-submit'
        ,submit = layero.find('iframe').contents().find('#'+ submitID);

        //监听提交
        iframeWindow.layui.form.on('submit('+ submitID +')', function(data){
            var loading2 = layer.load(2);
          var field = data.field; //获取提交的字段
          var ajax = new $ax(Feng.ctxPath + "/msgConfig/admin/receive", function (data) {
              Feng.success("修改成功!");
              window.location.reload();
              layer.close(loading2); //关闭弹层
              layer.close(index); //关闭弹层
          }, function (data) {
              Feng.error("修改失败!" + data.responseJSON.message + "!");
          },true);
          ajax.setData(field);
          ajax.start();
          
        });  
        
        submit.trigger('click');
      }
      ,btn2: function(index, layero){
 	   layer.close(loadingIndex);
      }
      ,cancel:function(index, layero){
 	   layer.close(loadingIndex);
      }
    });
}


   
</script>
@}
